package cn.bqjr.eily.shiro.spring.boot.filter;

import org.apache.shiro.web.filter.AccessControlFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Shiro公共访问过滤器
 */
public abstract class AbstractAccessControlFilter extends AccessControlFilter {
    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest,
                                      ServletResponse servletResponse,
                                      Object o) {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        /**
         * 不过滤浏览器自发请求
         */
        String method = request.getMethod();
        if (method.toUpperCase().equals("OPTIONS")) {
            return true;
        }

        return doIsAccessAllowed(request, (HttpServletResponse) servletResponse, o);
    }

    abstract protected boolean doIsAccessAllowed(HttpServletRequest request,
                                                 HttpServletResponse response,
                                                 Object o);
}
